package com.fhz.day012;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

public class MainActivity2 extends AppCompatActivity {

    private MyReceiver2 myReceiver2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);


//        myReceiver2 = new MyReceiver2();
//
//        IntentFilter intentFilter = new IntentFilter();
//        intentFilter.addAction("com.feng");
//        intentFilter.addAction("com.feng1");
//        intentFilter.addAction("com.feng2");
//
//        //动态注册
//        registerReceiver(myReceiver2,intentFilter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        unregisterReceiver(myReceiver2);
    }

    public void send(View view) {

        Intent intent = new Intent();
        //频道
        intent.setAction("com.feng");
        //内容
//        intent.putExtra("name","xiaoming");

        Bundle bundle = new Bundle();
        bundle.putString("name","小明");
        intent.putExtras(bundle);
        //发送广播
        sendBroadcast(intent);
    }

    public void send2(View view) {
        Intent intent = new Intent();
        //频道
        intent.setAction("com.feng1");
        //内容
//        intent.putExtra("name","xiaoming");
        Bundle bundle = new Bundle();
        bundle.putString("name","大明");
        intent.putExtras(bundle);


        sendOrderedBroadcast(intent,null);

    }
}